<?php
namespace app\controller\admin;

use think\Controller;
use think\facade\View;
use think\facade\Session;

class Application extends Controller
{
    /**
     * 前置执行的method
     * @var array
     */
    protected $beforeActionList = [
        'init' =>  ['except'=> ['login', 'logout', 'captcha', 'refresh']],
    ];

    public function initialize()
    {
        if (! Session::has('admin_login_id') || ! session('admin_login_id')) {
            $this->redirect('admin/login');
        }
    }

    /**
     * 共用拿出变量
     */
    protected function init()
    {
        View::share(['meta' => [], 'siteTitle' => '后台管理']);
    }

    public function formatResult($ret, $msg, $data = [])
    {
        return ['ret' => $ret, 'msg' => $msg, 'data' => $data];
    }
}
